
#import "LBData.h"
#import "LBPropertyUnit.h"

@implementation LBData

@synthesize musicVolume;
@synthesize soundVolume;
@synthesize gameDifficulty;
@synthesize score;
@synthesize money;
@synthesize honor;
@synthesize properties;


-(id)initWithMusicVolume:(float)mv SoundVolume:(float)sv GameDifficulty:(int)gdf Score:(int)sc Money:(int)my Honor:(int)hn
{
    if( !(self = [super init]))
    {
        return nil;
    }
    
    musicVolume = mv;
    soundVolume = sv;
    gameDifficulty = gdf;
    score = sc;
    money = my;
    honor = hn;
    
    properties = [[NSMutableArray alloc] initWithCapacity:LB_PROPERTIES_GROUPNUM*LB_PROPERTIES_GROUPSIZE];
    
    // Bomb
    LBPropertyUnit *propertyUnit = [[LBPropertyUnit alloc] initWithType:LB_PROPERTY_BOMB Level:1 Number:10 Value:LB_BOMB_LEVEL1_VALUE];
    [properties addObject:propertyUnit];
    
    propertyUnit = [[LBPropertyUnit alloc] initWithType:LB_PROPERTY_BOMB Level:2 Number:10 Value:LB_BOMB_LEVEL2_VALUE];
    [properties addObject:propertyUnit];
    
    propertyUnit = [[LBPropertyUnit alloc] initWithType:LB_PROPERTY_BOMB Level:3 Number:10 Value:LB_BOMB_LEVEL3_VALUE];
    [properties addObject:propertyUnit];
    
    // Color ball
    propertyUnit = [[LBPropertyUnit alloc] initWithType:LB_PROPERTY_COLORBALL Level:1 Number:10 Value:LB_COLORBALL_LEVEL1_VALUE];
    [properties addObject:propertyUnit];
    
    propertyUnit = [[LBPropertyUnit alloc] initWithType:LB_PROPERTY_COLORBALL Level:2 Number:0  Value:LB_COLORBALL_LEVEL1_VALUE];
    [properties addObject:propertyUnit];
    
    propertyUnit = [[LBPropertyUnit alloc] initWithType:LB_PROPERTY_COLORBALL Level:3 Number:0 Value:LB_COLORBALL_LEVEL1_VALUE];
    [properties addObject:propertyUnit];
    
    
    return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder
{
    [encoder encodeFloat:musicVolume forKey:DATA_KEY_NAME_MUSICVOLUME];
    [encoder encodeFloat:soundVolume forKey:DATA_KEY_NAME_SOUNDVOLUME];
    [encoder encodeInt:gameDifficulty forKey:DATA_KEY_NAME_GAMEDIFFICULTY];
    [encoder encodeInt:score forKey:DATA_KEY_NAME_SCORE];
    [encoder encodeInt:money forKey:DATA_KEY_NAME_MONEY];
    [encoder encodeInt:honor forKey:DATA_KEY_NAME_HONOR];
    [properties encodeWithCoder:encoder];
}


- (id)initWithCoder:(NSCoder *)decoder
{
    if( !(self = [super init]))
    {
        return nil;
    }
    
    musicVolume = [decoder decodeFloatForKey:DATA_KEY_NAME_MUSICVOLUME];
    soundVolume = [decoder decodeFloatForKey:DATA_KEY_NAME_SOUNDVOLUME];
    gameDifficulty = [decoder decodeIntForKey:DATA_KEY_NAME_GAMEDIFFICULTY];
    score = [decoder decodeIntForKey:DATA_KEY_NAME_SCORE];
    money = [decoder decodeIntForKey:DATA_KEY_NAME_MONEY];
    honor = [decoder decodeIntForKey:DATA_KEY_NAME_HONOR];
    
    properties = [[NSMutableArray alloc] initWithCoder:decoder];
    return self;
}

@end